package com.ballcat.spring.cloud.learning.controller;

import com.ballcat.spring.cloud.learning.common.CommonResult;
import com.ballcat.spring.cloud.learning.entity.Payment;
import com.ballcat.spring.cloud.learning.service.PaymentService;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.UUID;

/**
 * @author pengshun
 * @date 2022-04-04 17:33
 * @description
 */
@RestController
@RequestMapping("/payment")
public class PaymentController {

    @Resource
    private  PaymentService paymentService;

    @Value("${server.port}")
    private String serverPort;

    @PostMapping(value = "save")
    public CommonResult<Integer> save(@RequestBody Payment payment) {
        return CommonResult.ok(paymentService.save(payment));
    }

    @GetMapping(value = "getById")
    public CommonResult<Payment> getById(@RequestParam Integer id) {
        return CommonResult.ok(paymentService.getById(id), "访问8004");
    }

    @GetMapping(value = "zk")
    public String zookeeper() {
        return "spring cloud with zookeeper: " + serverPort + UUID.randomUUID().toString();
    }
}
